package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类相关")
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @ApiOperation("测试接口")
    @GetMapping("/hello")
    public String hello() {
        return "hello ingboog";
    }

    @ApiOperation("测试接口4 显示传入姓名")
    @PostMapping("/helloByName")
    public String helloByName(@ApiParam("姓名") @RequestPart("name-") String name) {
        return "hello springboog" + name;
    }


    @ApiOperation("测试接口2 显示异常信息")
    @GetMapping("/exception")
    public AppResult Exception() throws Exception {
        throw new Exception("这是一个Exception");
    }

    @ApiOperation("测试接口2 显示自定义信息")
    @GetMapping("/appexception")
    public AppResult appException() throws ApplicationException {
        throw new ApplicationException("这是一个ApplicationException");
    }
}